<?php
require_once(OC_App::getAppPath('company') . "/lib/quota.php");

if (!PFactory::isMasterUser()) {
   echo '您无权访问该资源';
   exit();
}

$order_id = JRequest::getInt('order_id', 0);

$model = new PCompanyModelQuota();
list($orderList, $pagination) = $model->getOrderList();

if (empty($orderList)) {
   echo '<div class="quota_nodata large yahei">历史订单为空</div>';
   exit();
} else {
?>
<div class="ordermenubox">
   <table width="100%" cellpadding="0" cellspacing="0" border="0">
      <tr>
      	 <th width="18%">订单编号</th>
         <th width="18%" align="left">订单内容</th>
         <th width="13%">价格</th>
         <th width="15%">下单日期</th>
         <th width="15%">有效期至</th>
         <th width="21%">操作</th>
      </tr>
   </table>  
   
   <table width="100%" cellpadding="0" cellspacing="0" border="0">
      <?php foreach ($orderList as $order): ?>
      <tr id="order_<?=$order->id?>">
         <td width="18%" align="center"><?=$order->order_num?></td>
         <td width="18%"><?=($order->order_type == 'sms_free' ? '<span style="color:#ff6600;">'.$order->order_content.'</span>' : $order->order_content)?></td>
         <td width="13%" align="center"><?=$order->order_type == 'upgrade' ? '--' : number_format($order->amount, 2) . '元'?></td>
         <td width="15%" align="center"><?=JHtml::_('date', $order->order_date, 'Y-m-d H:i')?></td>
         <td width="15%" align="center"><?=(isNullDate($order->expired_date) ? '--' : JHtml::_('date', $order->expired_date, 'Y-m-d'))?></td>
         <td width="21%" align="center" data-order_id="<?=$order->id?>">
            <?php 
            if ($order->status == 0) {
               echo '已取消';
            } elseif ($order->status == 100) {
               echo $order->order_type == 'sms_free' ? '赠送成功' : '购买成功';
            } elseif ($order->status == 1) {
            ?>
            <a href="javascript:;" class="uploadvabtn uploadReceipt">上传汇款凭证<?=(!empty($order->receipt_pic) ? '<i></i>' : '')?></a> <em class="line">|</em> <a href="javascript:;" class="cancelOrder">取消</a>
            <?php 
            }
            ?>
         </td>
      </tr>
      <?php endforeach; ?>
   </table>
</div>

<?php if ($pagination->pagesTotal > 1): ?>
<div id="orderListPagination"></div>
<script language="javascript" type="text/javascript">
   jQuery(document).ready(function() {
      jQuery.ajaxSetup({ cache: false });
      jQuery("#orderListPagination").pager({
         pageCount: <?php echo $pagination->pagesTotal; ?>,
         currentPage: <?php echo $pagination->pagesCurrent - 1; ?>
      }).delegate("li.active", "click", function(e) {
         var page = parseInt($(this).attr('page'));
         var url = getUrlQuery("<?=OC_Helper::linkTo('company','ajax/getorderlist.php')?>", "limitstart=" + (page * <?=$pagination->limit?>));
         var target = jQuery(this);
         jQuery.ajax({
            url: url,
            beforeSend: function(xhr, settings) {
               showLoading(target, settings, null, {button:true});
            },
            success: function(result) {
               jQuery("#orderListBody").html(result);
            }
         })
      }).parent().show();
   })
</script>
<?php endif; ?>

<?php 
}
?>